﻿IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[vrptEpalithefsiList]'))
DROP VIEW [vrptEpalithefsiList]
go
create view [vrptEpalithefsiList] as 
SELECT [S_N]
      ,[CLAIM_NO]
      ,[CL_NAME]
      ,[EPAL_NO]
      ,[EPAL_AMT]
      ,[EPAL_NOT_ACC]
      ,[EPAL_ACC_KAT]
      ,[EPAL_ACC_CO]
      ,[KAT_PERC_1] as KAT_PERC
      ,[CO_PERC_1] as CO_PERC
      ,[Priviledged],1 as pmttype
  FROM [CLAIMS]
  where isnull([KAT_PERC_1],0)>0 or isnull([CO_PERC_1],0)>0 
  union
  SELECT [S_N]
      ,[CLAIM_NO]
      ,[CL_NAME]
      ,[EPAL_NO]
      ,[EPAL_AMT]
      ,[EPAL_NOT_ACC]
      ,[EPAL_ACC_KAT]
      ,[EPAL_ACC_CO]
      ,[KAT_PERC_2] as KAT_PERC
      ,[CO_PERC_2] as CO_PERC
      ,[Priviledged],2 as pmttype
  FROM [CLAIMS]
  where isnull([KAT_PERC_2],0)>0 or isnull([CO_PERC_2],0)>0 
  union
  SELECT [S_N]
      ,[CLAIM_NO]
      ,[CL_NAME]
      ,[EPAL_NO]
      ,[EPAL_AMT]
      ,[EPAL_NOT_ACC]
      ,[EPAL_ACC_KAT]
      ,[EPAL_ACC_CO]
      ,[KAT_PERC_3] as KAT_PERC
      ,[CO_PERC_3] as CO_PERC
      ,[Priviledged],3 as pmttype
  FROM [CLAIMS]
  where isnull([KAT_PERC_3],0)>0 or isnull([CO_PERC_3],0)>0 
  union
  SELECT [S_N]
      ,[CLAIM_NO]
      ,[CL_NAME]
      ,[EPAL_NO]
      ,[EPAL_AMT]
      ,[EPAL_NOT_ACC]
      ,[EPAL_ACC_KAT]
      ,[EPAL_ACC_CO]
      ,[KAT_PERC_4] as KAT_PERC
      ,[CO_PERC_4] as CO_PERC
      ,[Priviledged],4 as pmttype
  FROM [CLAIMS]
  where isnull([KAT_PERC_4],0)>0 or isnull([CO_PERC_4],0)>0
   union
  SELECT [S_N]
      ,[CLAIM_NO]
      ,[CL_NAME]
      ,[EPAL_NO]
      ,[EPAL_AMT]
      ,[EPAL_NOT_ACC]
      ,[EPAL_ACC_KAT]
      ,[EPAL_ACC_CO]
      ,[KAT_PERC_5] as KAT_PERC
      ,[CO_PERC_5] as CO_PERC
      ,[Priviledged], 5 as pmttype
  FROM [CLAIMS]
  where isnull([KAT_PERC_5],0)>0 or isnull([CO_PERC_5],0)>0

go
